<?php
class Promote extends BZ_Controller
{
    public function _init()
    {
        $this->load->model('promotion_project_model','promotion_project');
    }
    
    public function topic()
    {
        $pernum = 10;
        $start = 0;
        $getData = $this->input->get();
        $getData['version'] = array(2);
        $this->data['total'] = $this->promotion_project->total($getData);
        $this->data['page_list'] = $this->promotion_project->page_list($pernum, $start, $getData);
        $this->load->view('home/promote/topic', $this->data);
    }
    
    public function ajaxTopic()
    {
        $pernum = 10;
        $start = $this->input->get('start');
        $getData = $this->input->get();
        $getData['version'] = array(2);
        $data['total'] = $this->promotion_project->total($getData);
        $data['page_list'] = $this->promotion_project->page_list($pernum, $start, $getData);
        echo json_encode(array(
            'html'=>$this->load->view('home/promote/topic', $data, true)
        ));exit;
    }
    
    public function ajaxPraise()
    {
        $id = $this->input->post('id');
        $qty = $this->input->post('qty');
        $isUpdate = $this->promotion_project->addToPraise($id);
        if ($isUpdate) {
            echo json_encode(array(
                'status'   => true,
                'messages' => ($qty+1)
            ));exit;
        } else {
            echo json_encode(array(
                'status'   => false,
                'messages' => '网络出现问题'
            ));exit;
        }
    }
}